package com.inns.position.kafka.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.inns.position.utils.DateUtil;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by phoenix on 2018/4/7.
 */
public class LocationInfo {

    private String IMSI;
    private Long timestamp;
    private String buildId;
    private String floorId;
    private Integer poiId;
    private float x;
    private float y;

    public LocationInfo() {
    }

    public LocationInfo(String value) {
        String[] split = value.split("\\*");
        setIMSI(split[0]);Integer.parseInt("-1");
        setTimestamp(Long.parseLong(split[1]));
        setBuildId(split[2]);
        setFloorId(split[3]);
        setPoiId(Integer.parseInt(split[4]));
        setX(Float.parseFloat(split[5]));
        setY(Float.parseFloat(split[6]));
    }

    @JsonIgnore
    public Map<String, String> getColumnValues() {
        Map<String, String> columnValues = new HashMap<>(8);
        columnValues.put("buildId", getBuildId());
        columnValues.put("poiId", getPoiId() + "");
        columnValues.put("IMSI", getIMSI());
        columnValues.put("floorId", getFloorId());
        columnValues.put("x", getX() + "");
        columnValues.put("y", getY() + "");
        return columnValues;
    }

    private String getTimestampStr() {
        return timestamp.toString().substring(0, 10);// 去掉毫秒
    }

    @JsonIgnore
    public String getRowKey() {
        return IMSI + "|" + getTimestampStr() + "|" + buildId + "|" + poiId;
    }

    @JsonIgnore
    public String getRowKeyShort() {
        return IMSI + "|" + getTimestampStr();// todo 建立在IMSI唯一的情况下
    }

    @JsonIgnore
    public String getRowKeyShortPoi() {
        return IMSI + "|" + getPoiId() + "|" + getTimestampStr();
    }

    @JsonIgnore
    public byte[] getRowKey2() {
        String date = DateUtil.format(timestamp, "yyMMddHHmm");
        byte[][] bs = {
                Bytes.toBytes(IMSI.hashCode()),
                Bytes.toBytes(Integer.parseInt(date)),
                Bytes.toBytes(buildId.hashCode()),
                Bytes.toBytes(poiId.hashCode())
        };
        return Bytes.add(bs);
    }

    @Override
    public String toString() {
        return "LocationInfo{" +
                "IMSI='" + IMSI + '\'' +
                ", timestamp=" + timestamp +
                ", buildId='" + buildId + '\'' +
                ", floorId='" + floorId + '\'' +
                ", poiId=" + poiId +
                ", x=" + x +
                ", y=" + y +
                '}';
    }

    public String getIMSI() {
        return IMSI;
    }

    public void setIMSI(String IMSI) {
        this.IMSI = IMSI;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public String getBuildId() {
        return buildId;
    }

    public void setBuildId(String buildId) {
        this.buildId = buildId;
    }

    public String getFloorId() {
        return floorId;
    }

    public void setFloorId(String floorId) {
        this.floorId = floorId;
    }

    public Integer getPoiId() {
        return poiId;
    }

    public void setPoiId(Integer poiId) {
        this.poiId = poiId;
    }

    public float getX() {
        return x;
    }

    public void setX(float x) {
        this.x = x;
    }

    public float getY() {
        return y;
    }

    public void setY(float y) {
        this.y = y;
    }
}
